#include "../comm.h"
class Solution {
public:
    int maximumLength(string s) {
        vector<int> v[26];
        int len = s.size();
        int cnt = 0;
        for(int i = 0; i < len; ++i)
        {
            cnt++;
            if(i + 1 == len || s[i] != s[i + 1])
            {
                v[s[i] - 'a'].push_back(cnt);
                cnt = 0;
            }
        }
        int ans = 0;
        for(auto& num: v)
        {
            if(num.empty()) continue;
            ranges::sort(num, greater());
            num.push_back(0);
            num.push_back(0);
            ans = max({ans, num[0] - 2, min(num[0] - 1, num[1]), num[2]});
        }
        return ans ? ans : -1;

    }
};